<!DOCTYPE html>
<html  lang="en">
<head>
    <meta charset="utf-8">
    <title>改变头像|私教预约系统</title>
    <link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        p{
            font-family: tahoma,geneva,sans-serif;
            font-size: 24px;
            text-align: center;
        }
        td{
            color:;
        }
        table{
            margin-top: 30px;
        }
    </style>
</head>
<input type="hidden" id="thePhotoPath">
<p>
    &ensp;
</p>
<p><font size="8">以下图片点击即可更改为头像</font></p>
<p>
    <input type="file" style="margin-left:80%" style="width: 200px;height:60px;" id="upFile">
</p>
<p>
    <button type="button" class="btn btn-info"  style="margin-left:80%"  id="selfDefine">确认选择</button>
</p>
<table align="center">
    <tr>
        <td><img src="../images/1.jpg" alt="图片加载失败" title="设置为头像" onclick="change1()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>

        <td><img src="../images/2.jpg" alt="图片加载失败" title="设置为头像" onclick="change2()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>

        <td><img src="../images/3.jpg" alt="图片加载失败" title="设置为头像" onclick="change3()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>

        <td><img src="../images/4.jpg" alt="图片加载失败" title="设置为头像" onclick="change4()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>

    </tr>
    <tr align="center" >

    </tr>

    <tr>
        <td><img src="../images/5.jpg" alt="图片加载失败" title="设置为头像" onclick="change5()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;;"></td>
        <td><img src="../images/6.jpg" alt="图片加载失败" title="设置为头像" onclick="change6()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>
        <td><img src="../images/7.jpg" alt="图片加载失败" title="设置为头像" onclick="change7()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>
        <td><img src="../images/8.jpg" alt="图片加载失败" title="设置为头像" onclick="change8()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>
    </tr>
    <tr align="center" >

    </tr>

    <tr>
        <td><img src="../images/9.jpg" alt="图片加载失败" title="设置为头像" onclick="change9()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>
        <td><img src="../images/10.jpg" alt="图片加载失败" title="设置为头像" onclick="change10()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>
        <td><img src="../images/11.jpg" alt="图片加载失败" title="设置为头像" onclick="change11()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>
        <td><img src="../images/12.jpg" alt="图片加载失败" title="设置为头像" onclick="change12()"
                 style="width: 200px;height: 200px;margin-left: 50px;margin-top: 50px;"></td>
    </tr>


</table>
</body>

<script src="../jquery/jquery-3.4.1.min.js"></script>
<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="../jquery/ajaxfileupload.js"></script>
<script type="text/javascript">

    jQuery(function(){

        jQuery("#selfDefine").click(function(){
            let f = jQuery("#upFile")[0].files[0];
            let n = jQuery("#u_name").val();
            let formData = new FormData();
            formData.append("file",f);
            formData.append("u_name",n);
            jQuery.ajax({
                type:"post",
                url:"/upPhoto",
                data:formData,
                processData: false,//jquery不处理数据
                contentType:false,//jquery不需要设置content-type的类型
                success:function(rst){
                    alert('上传成功，请点击保存');
                    jQuery("#thePhotoPath").val(rst);
                    change();
                },
                fail:function(rst){
                    alert("失败");
                }
            });

        });

    },"json")

    function change(){

        let currentTrainerId = $.cookie("trainerid");

        let store = jQuery("#thePhotoPath").val();

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change1(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/1.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change2(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/2.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change3(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/3.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change4(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/4.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change5(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/5.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change6(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/6.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change7(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/7.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change8(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/8.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change9(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/9.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change10(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/10.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change11(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/11.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }

    function change12(){
        let currentTrainerId = $.cookie("trainerid");

        let store = "/images/12.jpg";

        jQuery.post("/updateTrainerImage",{"trainerId": currentTrainerId, "trainerImage": store},function (rst) {

            if(rst=="修改成功")
            {
                window.location.href="trainerInfoEdit.html";
            }
        });
    }
</script>
</html>
